import * as NS from "../../Common/NetServices";
import { IsNull, IsNullOrWhiteSpace } from "../../TYLibrary/Common/GlobalExtend";
import { LoadingBasePage, LoadingBasePageData } from "../../Common/ModulePage/LoadingBasePage";
import { WXDataClassRuntimeDecorator } from "../../Common/EntityBase";

@WXDataClassRuntimeDecorator()
class IndexPageData extends LoadingBasePageData {
    public times: number = 3;
}
class IndexPage extends LoadingBasePage {
    public SaveLastPage: boolean = false;

    public Data = new IndexPageData();

    public async OnAppInitReady() {
        let user = this.App.ModuleManager.MemberManager.LoginUser;
        if (this.App.LaunchData.query.Isbutton && this.App.LaunchData.query.Isbutton == "true") {
            //按钮转发
            if (!IsNull(user) && !IsNullOrWhiteSpace(user.UNIONID)) {
                if (user.ISNEWUSER) {
                    //新用户
                } else {
                    //老用户
                }
            }
        }

        // console.log(this.App.ModuleManager.MemberManager.IsShowReceive);
        // console.log(user.ISRECEIVE, user.ISUPGRADE, "user.ISRECEIVE || user.ISUPGRADE");
        // if (!IsNull(user) && !IsNullOrWhiteSpace(user.UNIONID)) {
        //     if (!user.ISRECEIVE || user.ISUPGRADE) {
        //         this.App.ModuleManager.MemberManager.IsShowReceive = true;
        //     }
        // }
        //let Indexdata = await NS.QueryIndexData(user.UNIONID);
        //wx.setStorageSync("Indexdata", Indexdata);
    }

    public async ShowIndex(): Promise<void> {
        return new Promise<void>((resolve, reject) => {
            let r = setInterval(() => {
                if (this.m_Showtime <= 0) {
                    clearInterval(r);
                    wx.reLaunch({ url: this.App.IndexPageType });
                    resolve();
                }
            }, 1000);
        });
    }
}
Page(new IndexPage());
